package com.farah.lease.web.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.farah.lease.model.entity.ViewAppointment;
import com.farah.lease.web.app.mapper.ViewAppointmentMapper;
import com.farah.lease.web.app.service.ApartmentInfoService;
import com.farah.lease.web.app.service.ViewAppointmentService;
import com.farah.lease.web.app.vo.apartment.ApartmentItemVo;
import com.farah.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.farah.lease.web.app.vo.appointment.AppointmentItemVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 不爱跑步的法拉韶
 * @Date 2024-06-25__09:23
 **/
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment> implements ViewAppointmentService {
    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;
    @Autowired
    private ApartmentInfoService apartmentInfoService;

    @Override
    public List<AppointmentItemVo> listItemByUserId(Long userId) {
        return viewAppointmentMapper.listItemByUserId(userId);
    }

    @Override
    public AppointmentDetailVo getDetailById(Long id) {
        ViewAppointment viewAppointment=viewAppointmentMapper.selectById(id);

        ApartmentItemVo apartmentItemVo=apartmentInfoService.selectApartmentItemVoById(viewAppointment.getApartmentId());
        AppointmentDetailVo detailVo = new AppointmentDetailVo();
//        copyProperties是将一个Java对象的属性值复制到另一个Java对象中
        BeanUtils.copyProperties(viewAppointment, detailVo);
        detailVo.setApartmentItemVo(apartmentItemVo);
        return detailVo;
    }
}
